package gijoe.service;

import gijoe.dao.AdminDao;
import gijoe.dto.AbroadDto;
import gijoe.dto.ApplicationDto;
import gijoe.dto.AwdDto;
import gijoe.dto.BoardNoticeDto;
import gijoe.dto.BoardRecruitDto;
import gijoe.dto.CareerDto;
import gijoe.dto.CertiDto;
import gijoe.dto.ChartDto;
import gijoe.dto.ClubDto;
import gijoe.dto.CommcdDto;
import gijoe.dto.HopeDto;
import gijoe.dto.InfoDto;
import gijoe.dto.IntroDto;
import gijoe.dto.LangDto;
import gijoe.dto.ParttimeDto;
import gijoe.dto.SchDto;
import gijoe.dto.SubmitDto;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImple implements AdminService {
  
  @Autowired
  private SqlSession sqlSession;
  
  /* 공지사항 ------------------------------------------------------------------------- */
  // 공지사항 리스트 (다 불러오기)
  public List<BoardNoticeDto> noticeSelectAll(HashMap map) {
    AdminDao boardnotice = sqlSession.getMapper(AdminDao.class);
    List<BoardNoticeDto> list = boardnotice.noticeSelectAll(map);
    return list;
  }
  
  // 공지사항 한 개만!
  @Override
  public BoardNoticeDto noticeSelectOne(String notice_num) {
    AdminDao boardnotice = sqlSession.getMapper(AdminDao.class);
    BoardNoticeDto dto = boardnotice.noticeSelectOne(notice_num);
    return dto;
  }
  
  // 공지사항 등록
  @Override
  public void noticeInsert(BoardNoticeDto dto) {
    AdminDao boardnotice = sqlSession.getMapper(AdminDao.class);
    boardnotice.noticeInsert(dto);
  }
  
  // 공지사항 삭제
  @Override
  public void noticeDelete(BoardNoticeDto dto) {
    AdminDao boardnotice = sqlSession.getMapper(AdminDao.class);
    boardnotice.noticeDelete(dto);
    
  }
  
  // 공지사항 수정
  @Override
  public void noticeUpdate(BoardNoticeDto dto) {
    AdminDao boardnotice = sqlSession.getMapper(AdminDao.class);
    boardnotice.noticeUpdate(dto);
    System.out.println(dto.toString());
    
  }
  
  /* 채용공고 ------------------------------------------------------------------------- */
  @Override
  public List<BoardRecruitDto> recruitSelectAll(HashMap map) {
    AdminDao boardrecruit = sqlSession.getMapper(AdminDao.class);
    List<BoardRecruitDto> recruit_list = boardrecruit.recruitSelectAll(map);
    return recruit_list;
  }
  
  // 채용공고 리스트 선택 1개만 하는 거
  @Override
  public BoardRecruitDto recruitSelectOne(String rcrt_num) {
    AdminDao boardrecruit = sqlSession.getMapper(AdminDao.class);
    BoardRecruitDto dto = boardrecruit.recruitSelectOne(rcrt_num);
    return dto;
  }
  
  // 채용공고(경력,신입 => 코드 선택)
  @Override
  public List<CommcdDto> recruit_cdSelect() {
    AdminDao boardrecruit = sqlSession.getMapper(AdminDao.class);
    List<CommcdDto> recruit_list = boardrecruit.recruit_cdSelect();
    return recruit_list;
  }
  
  // 채용 공고 등록
  @Override
  public void recruitInsert(BoardRecruitDto dto) {
    AdminDao boardrecruit = sqlSession.getMapper(AdminDao.class);
    boardrecruit.recruitInsert(dto);
  }
  
  // 채용 공고 삭제
  @Override
  public void recruitDelete(BoardRecruitDto dto) {
    AdminDao boardrecruit = sqlSession.getMapper(AdminDao.class);
    boardrecruit.recruitDelete(dto);
  }
  
  // 채용 공고 수정
  @Override
  public void recruitUpdate(BoardRecruitDto dto) {
    AdminDao boardrecruit = sqlSession.getMapper(AdminDao.class);
    boardrecruit.recruitUpdate(dto);
    System.out.println(dto.toString());
  }
  
  /* 지원자 ------------------------------------------------------------------------- */
  // 지원자 조회
  @Override
  public List<ApplicationDto> appSelectAll(HashMap map) {
    AdminDao admindao = sqlSession.getMapper(AdminDao.class);
    List<ApplicationDto> app_list = admindao.applicationSelectAll(map);
    return app_list;
  }
  
  // 채용공고 셀렉트박스
  @Override
  public List<BoardRecruitDto> recruitSelectAllOption() {
    AdminDao boardrecruit = sqlSession.getMapper(AdminDao.class);
    List<BoardRecruitDto> recruit_list = boardrecruit.recruitSelectAllOption();
    return recruit_list;
  }
  
  // 지원자상세
  @Override
  public Map<String, Object> appSelectOne(String app_num) {
    
    AdminDao boardapp = sqlSession.getMapper(AdminDao.class);
    
    ApplicationDto applicationdto = boardapp.applicationSelectOne(app_num);
    InfoDto infodto = boardapp.infoSelectOne(app_num);
    List<SchDto> schdto = boardapp.schSelectAll(app_num);
    List<AbroadDto> abroaddto = boardapp.abroadSelectAll(app_num);
    List<CareerDto> careerdto = boardapp.careerSelectAll(app_num);
    List<ClubDto> clubdto = boardapp.clubSelectAll(app_num);
    List<ParttimeDto> parttimedto = boardapp.parttimeSelectAll(app_num);
    List<AwdDto> awddto = boardapp.awdSelectAll(app_num);
    List<CertiDto> certidto = boardapp.certiSelectAll(app_num);
    HopeDto hopedto = boardapp.hopeSelectOne(app_num);
    List<LangDto> langdto = boardapp.langSelectAll(app_num);
    IntroDto introdto = boardapp.introSelectOne(app_num);
    SubmitDto submitdto = boardapp.submitSelectOne(app_num);
    
    Map<String, Object> application = new HashMap<String, Object>();
    
    application.put("applicationdto", applicationdto);
    application.put("schdto", schdto);
    application.put("infodto", infodto);
    application.put("abroaddto", abroaddto);
    application.put("careerdto", careerdto);
    application.put("clubdto", clubdto);
    application.put("parttimedto", parttimedto);
    application.put("awddto", awddto);
    application.put("certidto", certidto);
    application.put("hopedto", hopedto);
    application.put("langdto", langdto);
    application.put("introdto", introdto);
    application.put("submitdto", submitdto);
    
    return application;
  }
  
  @Override
  public int getNoticeCount() {
    AdminDao admindao = sqlSession.getMapper(AdminDao.class);
    return admindao.getNoticeCount();
  }
  
  @Override
  public List<BoardNoticeDto> noticeSearch(HashMap map) {
    AdminDao admindao = sqlSession.getMapper(AdminDao.class);
    List<BoardNoticeDto> list = admindao.noticeSearch(map);
    return list;
  }
  
  @Override
  public int getNoticeSearch(String search) {
    AdminDao admindao = sqlSession.getMapper(AdminDao.class);
    return admindao.getNoticeSearch(search);
  }
  
  @Override
  public int getRecruitCount() {
    AdminDao admindao = sqlSession.getMapper(AdminDao.class);
    return admindao.getRecruitCount();
  }
  
  @Override
  public List<BoardRecruitDto> recruitSearch(HashMap map) {
    AdminDao admindao = sqlSession.getMapper(AdminDao.class);
    List<BoardRecruitDto> list = admindao.recruitSearch(map);
    return list;
  }
  
  @Override
  public int getRecruitSearch(String search) {
    AdminDao admindao = sqlSession.getMapper(AdminDao.class);
    return admindao.getRecruitSearch(search);
  }
  
  @Override
  public int getAppCount() {
    AdminDao admindao = sqlSession.getMapper(AdminDao.class);
    return admindao.getAppCount();
  }
  
  @Override
  public List<ApplicationDto> appSearch(HashMap map) {
    AdminDao admindao = sqlSession.getMapper(AdminDao.class);
    List<ApplicationDto> list = admindao.appSearch(map);
    return list;
  }
  
  @Override
  public int getAppSearch(String app_nm, String app_stat, String rcrt_num) {
    AdminDao admindao = sqlSession.getMapper(AdminDao.class);
    return admindao.getAppSearch(app_nm, app_stat, rcrt_num);
  }
  
  @Override
  public void passUpdate(String pass_list){
    AdminDao admindao = sqlSession.getMapper(AdminDao.class);
    System.out.println(pass_list);
    
    String[] array = pass_list.split(",");
    
    admindao.passUpdate(array);
  }
  // 통계 Start ==============================================================
  
  // 신입
  @Override
  public List<ChartDto> Chart_recruit_n() {
    AdminDao chartapp = sqlSession.getMapper(AdminDao.class);
    List<ChartDto> recruit_p = chartapp.Chart_recruit_n();
    return recruit_p;
  }
  
  // 경력
  @Override
  public List<ChartDto> Chart_recruit_p() {
    AdminDao chartapp2 = sqlSession.getMapper(AdminDao.class);
    List<ChartDto> recruit_n = chartapp2.Chart_recruit_p();
    return recruit_n;
  }
  
  // 성별 남자
  @Override
  public List<ChartDto> Chart_sex_man() {
    AdminDao chartapp3 = sqlSession.getMapper(AdminDao.class);
    List<ChartDto> sex_man = chartapp3.Chart_sex_man();
    return sex_man;
  }
  
  // 성별 여자
  @Override
  public List<ChartDto> Chart_sex_she() {
    AdminDao chartapp4 = sqlSession.getMapper(AdminDao.class);
    List<ChartDto> sex_she = chartapp4.Chart_sex_she();
    return sex_she;
  }
  
  // 나이 20대
  @Override
  public List<ChartDto> Chart_age_20() {
    AdminDao chartapp5 = sqlSession.getMapper(AdminDao.class);
    List<ChartDto> age_20 = chartapp5.Chart_age_20();
    return age_20;
  }
  
  // 년도별 2014년
  @Override
  public List<ChartDto> Chart_year_2014() {
    AdminDao chartapp6 = sqlSession.getMapper(AdminDao.class);
    List<ChartDto> year_2014 = chartapp6.Chart_year_2014();
    return year_2014;
  }
  
  // 통계 End ================================================================
  
}
